package main.剑指OfferⅠ;

import java.util.ArrayList;
import java.util.List;

public class Day24 {
    public static void main(String[] args) {
        System.out.println("剑指Offer14-Ⅰ.剪绳子");
        System.out.println("剑指Offer57-Ⅱ.和为s的连续正数序列");
        System.out.println("剑指Offer62.圆圈中最后剩下的数字");
    }
}

class Offer14_Ⅰ{
    public int cuttingRope(int n) {
        if (n==2) return 1;
        else if (n==3) return 2;
        int result=1;
        while (n>4){
            result*=3;
            n-=3;
        }
        result*=n;
        return result;
    }
}

class Offer57_Ⅱ{
    public int[][] findContinuousSequence(int target) {
        List<int[]> list=new ArrayList<>();
        int left=1,right=2;
        while (left<right){
            int sum=(right+left)*(right-left+1)/2;//区间和
            if (sum==target){//满足
                int[] cur=new int[right-left+1];
                for (int i=0,j=left;i< cur.length;i++,j++) cur[i]=j;
                list.add(cur);
                right++;
            }else if (sum>target) left++;//区间缩小
            else right++;//区间扩大
        }
        int[][] result=new int[list.size()][];
        for (int i=0;i< list.size();i++) result[i]=list.get(i);
        return result;
    }
}

class Offer62{
    public int lastRemaining(int n, int m) {
        int result=0;
        for (int i=1;i<=n;i++) result=(result+m)%i;
        return result;
    }
}